Cover TOC Chap Prev Chap Prev Fig Next Fig Next Chap

Chapter 9: Sensing Viewer Actions

../ch09/09fig02.gif
Figure 9.2

A cube that spins when the viewer touches it.

09fig02.wrl
Click on the image to view the VRML scene.

#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
    children [
    # Rotating Cube
        DEF Cube Transform {
            children Shape {
                appearance Appearance {
                    material Material { }
                }
                geometry Box { }
            }
        },
    # Sensor
        DEF Touch TouchSensor { },
    # Animation clock
        DEF Clock TimeSensor { cycleInterval 4.0 },
    # Animation path
        DEF CubePath OrientationInterpolator {
            key [ 0.0, 0.50, 1.0 ]
            keyValue [
                0.0 1.0 0.0  0.0,
                0.0 1.0 0.0  3.14,
                0.0 1.0 0.0  6.28
            ]
        }
    ]
}
ROUTE Touch.touchTime        TO Clock.set_startTime
ROUTE Clock.fraction_changed TO CubePath.set_fraction
ROUTE CubePath.value_changed TO Cube.set_rotation